﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
using Anata.AnataServerDataSetTableAdapters;
using System.Data.Odbc;

namespace AnataWCFService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Services : IService
    {
        DataSet dataSet;   

        public DataSet GetData(string sql)
        {
            try
            {
                OdbcConnection conn = new OdbcConnection("Dsn=PostgreSQL30;database=anatadbserver;server=localhost;port=5432;uid=postgres;pwd=root;sslmode=disable;readonly=0;protocol=7.4;fakeoidindex=0;showoidcolumn=0;rowversioning=0;showsystemtables=0;fetch=100;socket=4096;unknownsizes=0;maxvarcharsize=255;maxlongvarcharsize=8190;debug=0;commlog=0;optimizer=0;ksqo=1;usedeclarefetch=0;textaslongvarchar=1;unknownsaslongvarchar=0;boolsaschar=1;parse=0;cancelasfreestmt=0;extrasystableprefixes=dd_;lfconversion=1;updatablecursors=1;disallowpremature=0;trueisminus1=0;bi=0;byteaaslongvarbinary=0;useserversideprepare=0;lowercaseidentifier=0;gssauthusegss=0;xaopt=1");
                conn.Open();

                OdbcDataAdapter dataAdapter = new OdbcDataAdapter(sql, conn);
                dataSet = new DataSet();

                dataSet.Reset();
                dataAdapter.Fill(dataSet);
            }
            catch (Exception e)
            {
                throw e;
            }

            return dataSet;
        }

        //public Anata.AnataServerDataSet.karyawanDataTable GetKaryawanDataTable() {
        //    karyawanTableAdapter karyawan = new karyawanTableAdapter();
        //    Anata.AnataServerDataSet.karyawanDataTable dt = new Anata.AnataServerDataSet.karyawanDataTable();
        //    karyawan.Fill(dt);
        //    return dt;
        //}

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}
